package mk.com.ldm.corepoint.administration.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DB {
	private static DB db = null;
	private static Connection conn = null;
	protected DB(){
		getConnection();
	}
	
	public static ResultSet execSql(String sql) {
		Statement s = null;
		ResultSet rs = null;
		try {
			s = conn.createStatement();
			rs = s.executeQuery(sql);
		} catch (SQLException e) {
			return null;
		}
		return rs;
	}
	
	public static Statement insertSql(String sql){
		Statement s = null;
		try {
			s = conn.createStatement();
			s.executeUpdate(sql);
			
		} catch (SQLException e) {
			return null;
		}
		return s;
	}
	
	public static DB getInstance(){
		if(db==null)
			db = new DB();
		return db;
	}
	
	public Connection getConnection(){
		try{
			Class.forName("org.postgresql.Driver");
			conn = DriverManager.getConnection("jdbc:postgresql:corepoint", "postgres", "pass");
		}catch(Exception e){
			
		}
		return conn;
	}
}
